package com.lishe.lishe.lishe.module.me.others;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.module.me.bean.PhotoItem;

/**
 * Created by zhcasecom on 2017/9/17.
 */

public class ImageSelector extends RelativeLayout implements View.OnClickListener {

    private OnClickListner listner;
    private ImageView imageView, delete;

    public PhotoItem item;

    public ImageSelector(Context context, PhotoItem item, OnClickListner listner) {
        super(context);
        init(context);
        this.listner = listner;
        this.item = item;
    }

    public ImageSelector(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }
//    public  ImageSelector (Context context,AttributeSet attrs){
//
//    }

    private void init(Context context) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View imageSelector = inflater.inflate(R.layout.image_selector, null);
        this.addView(imageSelector);
        imageView = (ImageView) imageSelector.findViewById(R.id.image);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        delete = (ImageView) imageSelector.findViewById(R.id.delete);
        delete.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        this.setVisibility(GONE);
        listner.onclick(item);
    }

    public void setImageResource() {
        imageView.setImageURI(item.uri);
    }

    public interface OnClickListner {
        void onclick(PhotoItem item);
    }
}
